Miles Sound System SDK 7.2a

XMIDI Channel Lock (110)

Discussion

< 64: Release previously locked channel and restore default channel number mapping

>= 64: Seize ("lock") an unlocked, unprotected physical MIDI channel (2-9) for assignment to this logical channel # (11-16)

The Channel Lock controller is one of the more powerful Extended MIDI controllers. Channel locking allows the XMIDI drivers to play multiple XMIDI sequences simultaneously, which in turn permits the creation of impressive sound effects and musical "mixes."

When used with a value greater than or equal to 64, the Channel Lock controller attempts to seize, or "lock," the highest MIDI channel number recognized by the driver's supported synthesizer which has the fewest actively playing notes. Channels which are already locked are immune to relocking. Channels which have been "protected" against locking by use of the XMIDI Channel Lock Protect controller (111), are immune to seizure unless no other unlocked channels are available.

After a MIDI channel has been successfully locked, the driver maps the locked channel onto the MIDI channel in which the Channel Lock controller itself appeared. This means that all subsequent MIDI events sent on the same channel as the Channel Lock controller (the "logical" channel) will instead be transmitted on the newly locked (or "physical") channel.

This concept is perhaps best illustrated with a typical application of channel locking. Below is a list of events comprising a short XMIDI sequence to create a "machine gun" sound effect. (Timing and note velocity information has been omitted for simplicity).


Ch 02 Controller 114 = 1 ;XMIDI Patch Bank Select = 1
Ch 02 Patch = 5 ;MIDI Program Change to patch 5 ("gunshot")
Ch 02 Pitch Wheel 0 ;Pitch bend centered (no bend)
Ch 02 Controller 1 = 0 ;Modulation = 0
Ch 02 Controller 7 = 127 ;Volume = 127
Ch 02 Controller 10 = 64 ;Panpot = 64 (center of stereo field)
Ch 02 Controller 116 = 5 ;FOR loop = 1 to 5...
Ch 02 Note C 5 on ;...sound a brief "gunshot" note...
Ch 02 Note C 5 off
Ch 02 Controller 116 = 127 ;...NEXT loop

This "machine gun" sequence would be ideal for use as part of an arcade game's sound-effects arsenal, except for one serious drawback: what happens if MIDI channel 2 is already being used by a background music sequence, or perhaps another sound effect? The controller values and patch change in the sequence above would certainly have an unfavorable effect on a romantic violin solo playing on channel 2. The problem could be solved by setting aside a block of active MIDI channels for use with overlaid sound-effects sequences, but this might be an unacceptable compromise for applications requiring playback of any but the simplest XMIDI sequences.

Channel locking and remapping is a much more satisfactory solution. When composing sequences for the XMIDI standard, the composer could assign all tracks in sound effects and other overlaid sequences to any desired MIDI channel. If an XMIDI Channel Lock controller is then inserted before the first Channel Voice event in the channel, the MSS driver can temporarily reassign a physical MIDI channel to the logical channel number, preventing the channel's use by any other sequence being played for as long as it is needed by the sequence which "locked" the channel. A not-so-obvious benefit of this scheme is that all sound-effects sequences can safely share the same logical channel numbers, since only the physical channel numbers recognized by the synthesizer are vulnerable to usage conflicts.

With channel locking installed, the machine gun sound-effect sequence might look like this:


Ch 02 Controller 110 = 127 ;XMIDI Channel Lock (seize channel)
Ch 02 Controller 114 = 1 ;XMIDI Patch Bank Select = 1
Ch 02 Patch = 5 ;MIDI Program Change to patch 5 ("gunshot")
Ch 02 Pitch Wheel 0 ;Pitch bend centered (no bend)
Ch 02 Controller 1 = 0 ;Modulation = 0
Ch 02 Controller 7 = 127 ;Volume = 127
Ch 02 Controller 10 = 64 ;Panpot = 64 (center of stereo field)
Ch 02 Controller 116 = 5 ;FOR loop = 1 to 5...
Ch 02 Note C 5 on ;...sound a brief "gunshot" note...
Ch 02 Note C 5 off
Ch 02 Controller 116 = 127 ;...NEXT loop
Ch 02 Controller 110 = 0 ;XMIDI Channel Lock (release channel)

The sequence's new final event, a Channel Lock controller with the value 0, is actually unnecessary since all channels locked by a sequence are released automatically as soon as the sequence ends or playback is stopped. However, in sequences with multiple tracks, it is a good idea to explicitly release each locked channel as soon as it is no longer needed by the sequence, instead of waiting for all tracks to expire. This allows the XMIDI driver to restore the channel to the sequence from which it was "stolen," minimizing the disruption to the background music.

When a locked channel is released, either through a Channel Lock controller with a value below 64 or through a C call to the analogous AIL_release_channel function, the timbre bank, patch number, pitch wheel, and MIDI controllers in the channel are updated to their correct values before being returned to the service of the original sequence. This relieves the application of the responsibility of keeping track of these values while a channel is locked. Conversely, when a channel is locked by a Channel Lock controller or its complementary AIL_lock_channel function, the MIDI Sustain (Hold1) controller (64) in the channel is forced to its "off" condition and all notes playing in the channel are silenced. No other controller values or MIDI messages are initialized! It is essential for a sequence (or an application) which has just received a locked channel to initialize all MIDI parameters, including MIDI controllers likely to contain undesirable values, the XMIDI Patch Bank Select controller and MIDI Program Change number, and the MIDI pitch wheel, to appropriate values. (Avoid the temptation to accomplish this with MIDI Channel Mode messages such as All Notes Off or Reset All Controllers. Channel Mode messages may be interpreted differently by various synthesizers, and the XMIDI API code which maintains sequence state tables and other data structures makes no attempt to interpret them at all).

Next Topic (XMIDI Channel Lock Protect (111))

Previous Topic (XMIDI Sequence Branch (109))


Group: Extended MIDI Technical Reference
Related Functions: AIL_lock_channel, AIL_release_channel

For technical support, e-mail Miles3@radgametools.com
© Copyright 1991-2007 RAD Game Tools, Inc. All Rights Reserved.